import { http } from '../utils/http/index'

// 文章信息
export interface ArticleInfo {
  id: string
  title: string
  content: string
  articleCover: string
  publishTime: string
  publisher: string
  publisherFace: string
  readCount: number
}

// 文章搜索请求参数
export interface ArticleSearchRequest {
  pageNo: number
  pageSize: number
  keyword: string
}

// 文章搜索响应
export interface ArticleSearchResponse {
  totals: number
  totalPages: number
  list: ArticleInfo[]
}

// 文章详情
export interface ArticleDetail {
  id: string
  title: string
  contentHtml: string
  articleCover: string
  publishTime: string
  publisher: string
  publisherFace: string | null
}

/**
 * 搜索文章列表
 */
export async function searchArticles(params: ArticleSearchRequest): Promise<ArticleSearchResponse> {
  const response = await http.post('/portal/article/search', params)
  return response as ArticleSearchResponse
}

/**
 * 获取文章详情
 */
export async function getArticleDetail(articleId: string): Promise<ArticleDetail> {
  const response = await http.get(`/portal/article/detail?articleId=${articleId}`)
  return response as ArticleDetail
}

